import configure from '../config.js'
export default function(){
	
	return new Promise(async (resolve, reject) => {
		
		let host = location.protocol + '//' + window.location.host + '/'
		
		host = configure.h5.baseUrl
		
		let apiUrl = host  + 'api/v2/client/info'
		var [error, {data}] = await uni.request({
		        url: apiUrl,
		        method:'POST',
		        dataType:'json',
		        header: {
		        	'content-type': 'application/x-www-form-urlencoded', 
		        }
		    })
		
		if(error){
			uni.showToast({
				title: '获取client_id失败, 请刷新重试',
				icon: 'none'
			})
			reject()
		}
		
		if(data.status){
			const {client_id, secret_key} = data.data
			uni.setStorageSync('client_id', client_id)
			uni.setStorageSync('client_secret', secret_key)
		}else{
			uni.showToast({
				title: data.msg,
				icon: "none"
			})
		}
		
		resolve(data)
		
	})
	
}